*Merge Dictator decisions (democrats) 
egen you5dem0 = rowmax(Q87)
egen you15dem0 = rowmax(Q88)
egen you5dem20 = rowmax(Q89)
egen you15dem20 = rowmax(Q90)

*Merge Dictator decisions (republicans) 
egen you5rep0 = rowmax(Q1424)
egen you15rep0 = rowmax(Q1425)
egen you5rep20 = rowmax(Q1426)
egen you15rep20 = rowmax(Q1427)

/*
*X Score 
gen     xscore=  1  if you12other36== 2 & you24other36== 2
replace xscore=  0  if you12other36== 1 & you24other36== 2
replace xscore= -1  if you12other36== 1 & you24other36== 1

gen     xscoredem=   1 if you5dem20== 2 & you15dem20==2
replace xscoredem=   0 if you5dem20== 1 & you15dem20==2
replace xscoredem=  -1 if you5dem20== 1 & you15dem20==1

*Y Score 
gen     yscore= -1 if you12other0== 2 & you24other0== 2
replace yscore=  0 if you12other0== 1 & you24other0== 2
replace yscore=  1 if you12other0== 1 & you24other0== 1

gen     yscoredem= -1 if you5dem0== 2 & you15dem0== 2
replace yscoredem=  0 if you5dem0== 1 & you15dem0== 2
replace yscoredem=  1 if you5dem0== 1 & you15dem0== 1

*/


*XY Scores (democrat)
*X Score 
gen xscoredem=1 if you5dem20==2 & you15dem20==2
replace xscoredem=0 if you5dem20==1 & you15dem20==2
replace xscoredem=-1 if you5dem20==1 & you15dem20==1
*Y Score 
gen yscoredem=-1 if you5dem0==2 & you15dem0==2
replace yscoredem=0 if you5dem0==1 & you15dem0==2
replace yscoredem=1 if you5dem0==1 & you15dem0==1

*Generosity (democrat)
gen generosity_dem = xscoredem+yscoredem

*XY Scores (republican)
*X Score 
gen xscorerep=1 if you5rep20==2 & you15rep20==2
replace xscorerep=0 if you5rep20==1 & you15rep20==2
replace xscorerep=-1 if you5rep20==1 & you15rep20==1
*Y Score 
gen yscorerep=-1 if you5rep0==2 & you15rep0==2
replace yscorerep=0 if you5rep0==1 & you15rep0==2
replace yscorerep=1 if you5rep0==1 & you15rep0==1

*Generosity (republican)
gen generosity_rep = xscorerep+yscorerep

/*
*Scaling the EET for the Generosity Scale
 2 Altruistic
 1 MaxiMin, Kiss Up
 0 Selfish, IAV, Equality Averse
-1 Envy, Kick Down
-2 Spite
*/

*Types (democrat)
*Types 1=Sel 2=IAV 3= Maximin 4=ALt 5=Envy 6=Kissup 7=Spite 8=Kickdown 9=Equalaverse
gen typedem=1 if xscoredem==0 & yscoredem==0
replace typedem=2 if xscoredem==-1 & yscoredem==1
replace typedem=3 if xscoredem==0 & yscoredem==1
replace typedem=4 if xscoredem==1 & yscoredem==1
replace typedem=5 if xscoredem==-1 & yscoredem==0
replace typedem=6 if xscoredem==1 & yscoredem==0
replace typedem=7 if xscoredem==-1 & yscoredem==-1
replace typedem=8 if xscoredem==0 & yscoredem==-1
replace typedem=9 if xscoredem==1 & yscoredem==-1
*Types (republican)
*Types 1=Sel 2=IAV 3= Maximin 4=ALt 5=Envy 6=Kissup 7=Spite 8=Kickdown 9=Equalaverse
gen typerep=1 if xscorerep==0 & yscorerep==0
replace typerep=2 if xscorerep==-1 & yscorerep==1
replace typerep=3 if xscorerep==0 & yscorerep==1
replace typerep=4 if xscorerep==1 & yscorerep==1
replace typerep=5 if xscorerep==-1 & yscorerep==0
replace typerep=6 if xscorerep==1 & yscorerep==0
replace typerep=7 if xscorerep==-1 & yscorerep==-1
replace typerep=8 if xscorerep==0 & yscorerep==-1
replace typerep=9 if xscorerep==1 & yscorerep==-1

 
*Labels for the types (democrat)
gen labeltypedem="Selfish" if typedem==1
replace labeltypedem="Inequality Averse" if typedem==2
replace labeltypedem="MaxiMin" if typedem==3
replace labeltypedem="Altruistic" if typedem==4
replace labeltypedem="Envious" if typedem==5
replace labeltypedem="Kiss Up" if typedem==6
replace labeltypedem="Spiteful" if typedem==7
replace labeltypedem="Kick Down" if typedem==8
replace labeltypedem="Equality Averse" if typedem==9

*Labels for the types (republican)
gen labeltyperep="Selfish" if typerep==1
replace labeltyperep="Inequality Averse" if typerep==2
replace labeltyperep="MaxiMin" if typerep==3
replace labeltyperep="Altruistic" if typerep==4
replace labeltyperep="Envious" if typerep==5
replace labeltyperep="Kiss Up" if typerep==6
replace labeltyperep="Spiteful" if typerep==7
replace labeltyperep="Kick Down" if typerep==8
replace labeltyperep="Equality Averse" if typerep==9

tab labeltypedem, gen(labeltypedem)

gen Altruistic_Dem        = labeltypedem1
gen Envious_Dem           = labeltypedem2
gen Equality_Averse_Dem   = labeltypedem3
gen Inequality_Averse_Dem = labeltypedem4
gen Kick_Down_Dem         = labeltypedem5
gen Kiss_Up_Dem           = labeltypedem6
gen MaxiMin_Dem           = labeltypedem7
gen Selfish_Dem           = labeltypedem8
gen Spiteful_Dem          = labeltypedem9

tab labeltyperep, gen(labeltyperep)

gen Altruistic_Rep        = labeltyperep1
gen Envious_Rep           = labeltyperep2
gen Equality_Averse_Rep   = labeltyperep3
gen Inequality_Averse_Rep = labeltyperep4
gen Kick_Down_Rep         = labeltyperep5
gen Kiss_Up_Rep           = labeltyperep6
gen MaxiMin_Rep           = labeltyperep7
gen Selfish_Rep           = labeltyperep8
gen Spiteful_Rep          = labeltyperep9

*Variable Coding for Missing Data (for any reason, already coded in dataset)

gen missingdem = 1 if (Q87==. | Q88==. | Q89==. | Q90==.) & pidtxt~=2
replace missingdem = 0 if Altruistic_Dem~=.
replace missingdem = 1 if Altruistic_Dem==. & pidtxt==1
replace missingdem = 1 if Altruistic_Dem==. & pidtxt==3
replace missingdem = . if pidtxt==.

gen nonresponsedem = 1 if (Q87==. | Q88==. | Q89==. | Q90==.) & pidtxt~=2
replace nonresponsedem = 0 if Altruistic_Dem~=.
replace nonresponsedem = . if pidtxt==.
replace nonresponsedem = 0 if nonresponsedem~=1 & missingdem~=.

gen missingrep = 1 if (Q1424==. | Q1425==. | Q1426==. | Q1427==.) & pidtxt~=1
replace missingrep = 0 if Altruistic_Rep~=.
replace missingrep = 1 if Altruistic_Rep==. & pidtxt==2
replace missingrep = 1 if Altruistic_Rep==. & pidtxt==3
replace missingrep = . if pidtxt==.

gen nonresponserep = 1 if (Q1424==. | Q1425==. | Q1426==. | Q1427==.) & pidtxt~=1
replace nonresponserep = 0 if Altruistic_Rep~=.
replace nonresponserep = . if pidtxt==.
replace nonresponserep = 0 if nonresponserep~=1 & missingrep~=.

*People without clear preferences (see also "unclear preferences.xls)

gen nopref1121d=1 if Q87==1 & Q88==1 & Q89==2 & Q90==1
gen nopref1221d=1 if Q87==1 & Q88==2 & Q89==2 & Q90==1
gen nopref2111d=1 if Q87==2 & Q88==1 & Q89==1 & Q90==1
gen nopref2112d=1 if Q87==2 & Q88==1 & Q89==1 & Q90==2
gen nopref2121d=1 if Q87==2 & Q88==1 & Q89==2 & Q90==1
gen nopref2122d=1 if Q87==2 & Q88==1 & Q89==2 & Q90==2
gen nopref2221d=1 if Q87==2 & Q88==2 & Q89==2 & Q90==1

gen noprefdem = 1 if nopref1121d==1 | nopref1221d==1 | nopref2111d==1 | nopref2112d==1 | nopref2121d==1 | nopref2122d==1 | nopref2221d==1
replace noprefdem = 0 if noprefdem~=1 & missingdem~=.

gen nopref1121r=1 if Q1424==1 & Q1425==1 & Q1426==2 & Q1427==1
gen nopref1221r=1 if Q1424==1 & Q1425==2 & Q1426==2 & Q1427==1
gen nopref2111r=1 if Q1424==2 & Q1425==1 & Q1426==1 & Q1427==1
gen nopref2112r=1 if Q1424==2 & Q1425==1 & Q1426==1 & Q1427==2
gen nopref2121r=1 if Q1424==2 & Q1425==1 & Q1426==2 & Q1427==1
gen nopref2122r=1 if Q1424==2 & Q1425==1 & Q1426==2 & Q1427==2
gen nopref2221r=1 if Q1424==2 & Q1425==2 & Q1426==2 & Q1427==1

gen noprefrep = 1 if nopref1121r==1 | nopref1221r==1 | nopref2111r==1 | nopref2112r==1 | nopref2121r==1 | nopref2122r==1 | nopref2221r==1
replace noprefrep = 0 if noprefrep~=1 & missingrep~=.
